(function($, T){

$.fn.pmTable = function(options){//ä¸åºå­ä¸ºä¸»çç©æéæ©è¡¨æ ¼
    var defaults = {};
    var opts = $.extend({}, defaults, options);
    this.list = [];

    this.getRow = opts["getRow"];
    this.getTypeCn = function(t){
        return pmTypeMap[t];
    }
    this.add = function(data){
        var tr = this.getRow(data, T);
        this.append(tr);
        this.renderNo();
        this.list.push(data);
    }
    this.remove = function(id){
        this.find("tbody tr").each(function(){
            var d = $(this).data("id");
            if(d == id){
                $(this).remove();
            }
        })
        for(var i = 0; i < this.list.length; i++){
            var item = this.list[i];
            if(item.id == id){
                this.list.splice(i, 1);
                i--;
            }
        }
    }
    this.renderNo = function(){
        this.find("tbody tr").each(function(i){
          $(this).find("td").eq(0).text(i < 9? "0" + (i + 1): i + 1);
        })
    }
    this.getList = function(){
        this.syncData();
        return T.dataCopy(this.list);
    }
    this.getIds = function(){
        var arr = T.map(this.list, function(data){
            return data.id;
        })
        return arr.join(",")
    }
    this.syncData = opts["syncData"] || function(){
        var dataMap = T.toKMap(this.list, "id");
        this.find("tbody tr").each(function(i){
          var id = $(this).data("id");
          var d = $(this).find("input").val();
          dataMap[id].outNumber = d;
        })
    }
    this.init = function(url){
        $.post(url, {}, function(data){
            if(data.code == 0){
                var list = data.data;
                for(var i = 0; i < list.length; i++){
                    this.add(list[i]);
                }
            }
        })
    }
    this.clearList = function(){
        this.list.length = 0;
    }
    return this;
}

})(jQuery, window.iUtils)